<!--
* @Description: 序列管理 - 表单
* @Author: DSY
* @Date: 2022-05-15 18:18:40
* @LastEditors: DSY
* @LastEditTime: 2022-05-15 18:18:40
-->
<template>
  <tw-dialog
    v-model="visible"
    :title="title"
    :loading="loading"
    width="600px"
    height="400px"
    @close="handleClose"
  >
    <el-form
      ref="dbFormRef"
      :model="dbForm"
      :rules="rules"
      label-width="90px"
      :disabled="action === 'view'"
    >
      <el-row>
        <el-col :span="12">
          <el-form-item label="编码" prop="code">
            <el-input v-model="dbForm.code" clearable placeholder="请输入编码"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="名称" prop="name">
            <el-input v-model="dbForm.name" clearable placeholder="请输入名称"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="前缀" prop="prefix">
            <el-input
              v-model="dbForm.prefix"
              clearable
              placeholder="请输入前缀"
              @change="getExample()"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="日期规则" prop="dateRule">
            <el-select
              v-model="dbForm.dateRule"
              clearable
              placeholder="请选择日期规则"
              @change="getExample()"
            >
              <tw-dic dicKey="TWB_SEQUENCE_DATA_RULE"></tw-dic>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="分隔符" prop="splitCode">
            <el-select
              v-model="dbForm.splitCode"
              clearable
              placeholder="请选择分隔符"
              @change="getExample()"
            >
              <tw-dic dicKey="TWB_SEQUENCE_SEQ_CODE"></tw-dic>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="自动刷新" prop="autoRefresh">
            <el-tooltip
              class="box-item"
              effect="dark"
              content="如果开启自动刷新，系统会根据时间格式进行更新"
              placement="top-start"
            >
              <el-switch
                v-model="dbForm.autoRefresh"
                :active-value="1"
                :inactive-value="2"
              ></el-switch>
            </el-tooltip>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="序列位数" prop="seqCount">
            <el-input-number
              v-model="dbForm.seqCount"
              clearable
              placeholder="请输入序列位数"
              @change="getExample()"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="步长" prop="seqStep">
            <el-input-number
              v-model="dbForm.seqStep"
              clearable
              placeholder="请输入步长"
              @change="getExample()"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="下一个" prop="seqNext">
            <el-input-number v-model="dbForm.seqNext" clearable placeholder="请输入下一个" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col>
          <div class="div_example">
            <span>样例：</span><span>{{ codeExampleStr }}</span>
          </div>
        </el-col>
      </el-row>
    </el-form>

    <template #footer>
      <el-button @click="handleReset(true)">取 消</el-button>
      <el-button v-if="action === 'add'" type="warning" @click="handleSubmit(true)">
        提交并继续
      </el-button>
      <el-button v-if="action !== 'view'" type="primary" @click="handleSubmit(false)">
        提 交
      </el-button>
    </template>
  </tw-dialog>
</template>

<script src="./useForm.ts"></script>

<style scoped lang="scss">
  .div_example {
    text-align: center;
    font-size: 20px;
    width: 80%;
    height: 50px;
    background: antiquewhite;
    margin: 20px auto;
    line-height: 50px;
    font-weight: bold;
    color: #f78a06;
  }
</style>
